package com.whh.zuowen.count.listener;

import com.whh.zuowen.count.event.ZuowenCountEvent;
import com.whh.zuowen.service.ZuowenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class ZuowenCountListener { //implements ApplicationListener<ZuowenCountEvent> {

    @Autowired
    ZuowenService zuowenService;

    @Async
    @EventListener
    public synchronized void onApplicationEvent(ZuowenCountEvent zuowenCountEvent) {
        Integer id = zuowenCountEvent.getId();
        zuowenService.countPlus(id);
    }
}
